package helloWorld;

import org.mt4j.MTApplication;
import org.mt4j.components.MTCanvas;
import org.mt4j.components.interfaces.IMTComponent3D;
import org.mt4j.components.visibleComponents.shapes.MTRectangle;
import org.mt4j.components.visibleComponents.widgets.MTImage;
import org.mt4j.input.inputProcessors.IGestureEventListener;
import org.mt4j.input.inputProcessors.MTGestureEvent;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
import org.mt4j.input.inputProcessors.componentProcessors.zoomProcessor.ZoomEvent;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;


public class ArtistGestureListener implements IGestureEventListener {
	private MTApplication mtApplication;
	private Controller controller;
	private ArtistScene artistScene;
	
	private boolean tapHappened;
	
	public ArtistGestureListener(MTApplication mtApplication, ArtistScene artistScene){
		this.mtApplication = mtApplication;
		controller = Controller.getInstance();
		this.artistScene = artistScene;
		tapHappened = false;
	}

	@Override
	public boolean processGestureEvent(MTGestureEvent ge) {
		if(ge instanceof TapEvent){
			tapHappened = true;
			TapEvent te = (TapEvent)ge;
			IMTComponent3D target = te.getTargetComponent();
			if(target instanceof Artist){
				Artist artist = (Artist) target;
				switch (te.getTapID()) {
				case TapEvent.BUTTON_DOWN:
					System.out.println("Button down state on " + target);
					break;
				case TapEvent.BUTTON_UP:
					System.out.println("Button up state on " + target);
					break;
				case TapEvent.BUTTON_CLICKED:
					artistScene.updateArtist(artist.getName());
					System.out.println("Clicked " + artist.getName());
					break;
				default:
					break;
				}
				
			} else if(target instanceof MTImage){
				// go back
				if(target.getName() == "artistsceneBACK"){
					mtApplication.changeScene(mtApplication.getScene("LetterScene"));
				}
			}
		} else if (ge instanceof ZoomEvent){
			// tap must be happened
			ZoomEvent ze = (ZoomEvent)ge;
			if(ze.getTargetComponent().getName() == "Main Canvas")
			{
				if(ze.getCamZoomAmount() >= 10)
					;//mtApplication.changeScene(mtApplication.getScene("LetterScene"));
			}
			else{
				if(tapHappened){
					Artist target = (Artist)ze.getTargetComponent();
					System.out.println("Change to artist " + target.getName());
					controller.setCurrentArtist(target.getName());
					mtApplication.changeScene(mtApplication.getScene("AlbumScene"));
				}
			}
			
		}
		return false;

	}
	
	
}
